<extend name="Public/baseConf"/>
<block name="breadcrumb"> 
	<div class="row wrapper border-bottom white-bg page-heading">
	    <div class="col-lg-6">
	        <h2>导航排序</h2>
	        <ol class="breadcrumb">
	            <li><a href="{:U('index/index')}">首页</a></li>
	            <li><a href="{:U('Channel/index')}">导航管理</a></li>
	            <li class="active">
	                <strong>导航排序</strong>
	            </li>
	        </ol>
	    </div>
	    <div class="col-lg-6">
            <div class="title-action">
 				<button class="sort_confirm btn btn-primary" type="button">
 				<i class="fa fa-check"></i>保存</button>
	            <a class="sort_cancel btn btn-warning" type="submit" href="{:U('index',array('pid'=>I('pid')))}">
	            <i class="fa fa-reply"></i>返回</a>
            </div>
        </div>
	</div>
</block>
<block name="body">
<input id="channelindex" value="{:U('index',array('pid'=>I('pid')))}">
    <div class="row">
        <div class="col-lg-12">
			<div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>导航排序</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row">
                    <form action="{:U('sort')}" method="post">
                        <div class="col-sm-6 b-r"> 
							<select value="" size="16" class="form-control">
								<volist name="list" id="vo">
									<option class="ids" title="{$vo.title}" value="{$vo.id}">{$vo.title}</option>
								</volist>
							</select>
                        </div>
                        <div class="col-sm-6"> 
							<button class="top btn btn-success" type="button"><i class="fa fa-chevron-up"></i> 第 一</button><br>
							<button class="up btn btn-success" type="button"><i class="fa fa-arrow-up"></i> 上 移</button><br>
							<button class="down btn btn-danger" type="button"><i class="fa fa-arrow-down"></i> 下 移</button><br>
							<button class="bottom btn btn-danger" type="button"><i class="fa fa-chevron-down"></i> 最 后</button><br>
							<input type="hidden" name="ids">
                        </div>
                    </form>
                    </div>
                </div>
            </div>
          </div>
    </div>
</block>

<block name="script">
	<script type="text/javascript">
		//导航高亮
		highlight_subnav('{:U('Channel/index')}');
		$(function(){
			sort();
			$(".top").click(function(){
				rest();
				$("option:selected").prependTo("select");
				sort();
			})
			$(".bottom").click(function(){
				rest();
				$("option:selected").appendTo("select");
				sort();
			})
			$(".up").click(function(){
				rest();
				$("option:selected").after($("option:selected").prev());
				sort();
			})
			$(".down").click(function(){
				rest();
				$("option:selected").before($("option:selected").next());
				sort();
			})
			$(".search").click(function(){
				var v = $("input").val();
				$("option:contains("+v+")").attr('selected','selected');
			})
			function sort(){
				$('option').text(function(){return ($(this).index()+1)+'.'+$(this).text()});
			}

			//重置所有option文字。
			function rest(){
				$('option').text(function(){
					return $(this).text().split('.')[1]
				});
			}

			//获取排序并提交
			$('.sort_confirm').click(function(){
				var arr = new Array();
				$('.ids').each(function(){
					arr.push($(this).val());
				});
				$('input[name=ids]').val(arr.join(','));
				$.post(
					$('form').attr('action'),
					{
					'ids' :  arr.join(',')
					},
					function(data){
						if (data.status) {
	                        updateAlert(data.info + ' 页面即将自动跳转~','alert-success');
	                    }else{
	                        updateAlert(data.info,'alert-success');
	                    }
	                    setTimeout(function(){
	                    	window.location.href=$('#channelindex').val();
	                    },1500);
	                    
					},
					'json'
				);
			});

			//点击取消按钮
			$('.sort_cancel').click(function(){
				window.location.href = $(this).attr('url');
			});
		})
	</script>
</block>